package com.yuzhenxin.coursesystem.controller.schedule;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.framework.common.pojo.R;
import com.yuzhenxin.coursesystem.config.EndPoints;
import com.yuzhenxin.coursesystem.controller.schedule.vo.ScheduleCreateReqDto;
import com.yuzhenxin.coursesystem.controller.schedule.vo.ScheduleQueryReqDto;
import com.yuzhenxin.coursesystem.entity.ScheduleDO;
import com.yuzhenxin.coursesystem.service.ScheduleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated
@Tag(name = "教师开课管理")
@RestController
public class ScheduleController {

    @Resource
    private ScheduleService scheduleService;

    @GetMapping(EndPoints.SCHEDULE_GETBYID)
    public R<ScheduleDO> getById(@RequestParam("id") Integer id) {
        ScheduleDO scheduleDO = scheduleService.getById(id);
        return R.success(scheduleDO);
    }

    @Operation(summary = "根据教师姓名和课程名称模糊查询课程")
    @PostMapping(value = EndPoints.SCHEDULE_SELECTPAGE, consumes = MediaType.APPLICATION_JSON_VALUE)
    public R<IPage<ScheduleDO>> selectPage(@Valid @RequestBody ScheduleQueryReqDto reqDto) {
        IPage<ScheduleDO> scheduleIPage = scheduleService.selectPage(reqDto);
        return R.success(scheduleIPage);
    }

    @PostMapping(value = EndPoints.SCHEDULE_ADD, consumes = MediaType.APPLICATION_JSON_VALUE)
    public R<?> add(@Valid @RequestBody ScheduleCreateReqDto reqDto) {
        scheduleService.add(reqDto);
        return R.success();
    }

    @PutMapping(value = EndPoints.SCHEDULE_UPDATEBYID, consumes = MediaType.APPLICATION_JSON_VALUE)
    public R<?> updateById(@RequestBody ScheduleDO scheduleDO) {
        scheduleService.updateById(scheduleDO);
        return R.success();
    }

    @Operation(summary = "删除多个排课信息")
    @DeleteMapping(value = EndPoints.SCHEDULE_REMOVEBYIDS, consumes = MediaType.APPLICATION_JSON_VALUE)
    public R<?> removeByIds(@NotEmpty @RequestBody List<Integer> idList) {
        scheduleService.removeByIds(idList);
        return R.success();
    }

}
